/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.notaria.guerrasalas.bc;

import com.notaria.guerrasalas.be.ClienteJuridico;
import gob.satt.comun.jpa.Command;
import java.util.List;
import javax.persistence.EntityManager;
import oracle.toplink.essentials.config.HintValues;
import oracle.toplink.essentials.config.TopLinkQueryHints;

/**
 *
 * @author Administrador
 */
public class ListarClientesJuridicosCommand implements Command<List<ClienteJuridico>> {

    private String razonSocial;

    public ListarClientesJuridicosCommand(String razonSocial) {
        this.razonSocial = razonSocial;
    }

    @Override
    public List<ClienteJuridico> execute(EntityManager em) throws Exception {
        List<ClienteJuridico> clientes = null;
        if (razonSocial != null && !razonSocial.trim().equals("")) {
            clientes = (List<ClienteJuridico>) em.createQuery("SELECT object(o) FROM ClienteJuridico o WHERE UPPER(o.nombres) Like :razonSocial")
                    .setParameter("razonSocial", "%" + razonSocial.toUpperCase() + "%")
                    .setHint(TopLinkQueryHints.REFRESH, HintValues.TRUE)
                    .getResultList();
        } else {
            clientes = (List<ClienteJuridico>) em.createQuery("SELECT object(o) FROM ClienteJuridico o")
                    .setHint(TopLinkQueryHints.REFRESH, HintValues.TRUE)
                    .getResultList();
        }
        return clientes;
    }
}
